defmodule Giom.Repo.Migrations.CreateStocktrans do
  use Ecto.Migration

  def change do
    create table(:stocktrans) do
      add :doc_no, references(:ptrans,type: :string, column: :doc_no, on_delete: :nothing), null: false
      add :trans_date, :utc_datetime
      add :create_date, :utc_datetime
      add :edit_date, :utc_datetime
      add :price, :decimal
      add :price_vat, :decimal
      add :vat, :decimal
      add :stock_code, references(:stocks,type: :string, column: :code, on_delete: :nothing), null: false
      add :source_code, references(:points,type: :string, column: :point_code, on_delete: :nothing), null: false
      add :target_code, references(:points,type: :string, column: :point_code, on_delete: :nothing), null: false
      add :m_unit,  :string,size: 2
      add :doc_type,  :string,size: 1
      add :comment,  :string
      add :row_no,  :integer
      add :qty, :decimal, null: false
      add :i_qty, :decimal
      add :i_qty2, :decimal
      add :i_qty3, :decimal
      add :discount, :decimal,default: 0.0
      add :discount2, :decimal,default: 0.0
      add :discount3, :decimal,default: 0.0
      add :wbill_no, :string
	  add :wbill_date, :utc_datetime
	  add :track_code, :string
	  add :track_code2, :string
	  #add :trans_resp, :string / user tablo bağlanacak
	  #add :ptrans_code, :string / cari hareket tablosuna bağlanacak
	   
      timestamps()
    end

    create index(:stocktrans, [:stock_code])
    create index(:stocktrans, [:source_code])
    create index(:stocktrans, [:target_code])
    create index(:stocktrans, [:doc_no])
  end
end
